import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction

class ReleaseInfoTask extends DefaultTask {

    ReleaseInfoTask() {
        // 1、在构造器中配置了该 Task 对应的 Task group，即 Task 组，并为其添加上了对应的描述信息。
        group = "version_manager"
        description = "release info update"
    }

    // 2、在 gradle 执行阶段执行
    @TaskAction
    void action() {
        updateVersionInfo()
    }

    private void updateVersionInfo() {
        // 3、从 realeaseInfo Extension 属性中获取相应的版本信息
        def versionName = project.extensions.releaseInfo.versionName
        def versionCode = project.extensions.releaseInfo.versionCode
        def versionInfo = project.extensions.releaseInfo.versionInfo
        def inputFileName = project.extensions.releaseInfo.inputFileName
        def outputFileName = project.extensions.releaseInfo.outputFileName

        println versionName
        println versionCode
        println versionInfo
        println inputFileName
        println outputFileName

        //copy文件
        def inputFile = new File(inputFileName)
        def outputFile = new File(outputFileName)
        println inputFile.absolutePath
        println outputFile.absolutePath
        println inputFile.exists()

    }

}